package org.springblade.common.io;

import java.io.IOException;
import java.io.OutputStream;

public class XorOutputStream extends OutputStream{
	
	private OutputStream outputStream;

	
	public XorOutputStream(OutputStream outputStream) {
		this.outputStream=outputStream;
	}


	@Override
	public void write(int b) throws IOException {
		outputStream.write(b^XorInputStream.KEY);
	}

	@Override
	public void write(byte[] b, int off, int len) throws IOException {
		for (int i = off; i < off+len; i++) {
            b[i] = (byte) (b[i]^XorInputStream.KEY);
        }
		outputStream.write(b, off, len);
	}


	@Override
	public void write(byte[] b) throws IOException {
		this.write(b,0,b.length);
	}


	@Override
	public void flush() throws IOException {
		outputStream.flush();
	}


	@Override
	public void close() throws IOException {
		outputStream.close();
	}
	
	
	
	
	
}
